package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Activity;
import cn.wolfcode.domain.ActivityItem;
import cn.wolfcode.service.IActivityItemService;
import cn.wolfcode.service.IActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/activityItem")
public class ActivityItemController {

    @Autowired
    private IActivityItemService activityItemService;
    @Autowired
    private IActivityService activityService;


    @RequestMapping("/input")
    public String list(Model model, Long activityItemId){
        List<ActivityItem> list = activityItemService.selectByActivityItemId(activityItemId);
        Activity activity = activityService.selectById(activityItemId);
        model.addAttribute("activityItem",list);
        model.addAttribute("activity",activity);
        return "activityItem/input";
    }

    @RequestMapping("/show")
    public String show(Model model,Long optionsRadios,Long activityId){
        String msg = activityItemService.insetRelation(optionsRadios,activityId);
        List<ActivityItem> list = activityItemService.selectByActivityItemId(activityId);
        //求投票总人数
        int num = 0 ;
        for (ActivityItem a:list){
            num = num + a.getNum();
        }
        model.addAttribute("activityItems",list);
        model.addAttribute("voteMsg",msg);
        model.addAttribute("num",num);

        return "activityItem/show";
    }
}
